package com.yicong.ants.bean.scenic;

import android.graphics.Color;
import android.text.TextUtils;

import com.cchao.simplelib.core.Logs;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.GregorianCalendar;

/**
 * 预约
 * @author cchao
 * @version 2019-08-02.
 */
public class AppointBean {

    /**
     * advance_id : 4846
     * scenic_id : 156
     * advance_date : 2017-08-25
     * status : 2
     * cancel_reason : null
     * scenic_name : 秦始皇兵马俑
     * thumbnail : XXX.png
     * address : 陕西省西安市
     */

    private String advance_id;
    private String scenic_id;
    private String advance_date;
    private int status;
    private String cancel_reason;
    private String scenic_name;
    private String thumbnail;
    private String address;

    private boolean cancelable = false;
    private boolean ticketAble = false;
    private String statusStr;
    private int statusColor;

    public AppointBean() {
    }

    public String getStatusStr() {
        // 1:待审核  2:审核成功  3:取消预约]
        switch (status) {
            case 1:
                return "待审核";
            case 2:
                return "审核成功";
            case 3:
                return "取消预约";
        }
        return "待审核";
    }

    public int getStatusColor() {
        // 1:待审核  2:审核成功  3:取消预约]
        switch (status) {
            case 1:
                return Color.parseColor("#229FFD");
            case 2:
                return Color.parseColor("#00CDAC");
            case 3:
                return Color.parseColor("#FC6973");
        }
        return Color.parseColor("#229FFD");
    }

    public String getCancel_reason() {
        return cancel_reason == null ? "" : cancel_reason;
    }

    public boolean getCancelable() {
        if (status <= 2 && getCancelLegal(advance_date)) {
            return true;
        }
        return false;
    }

    public boolean isCancelable() {
        return getCancelable();
    }

    /**
     * 判断取消预约景区是否合法
     * 需要在预约景区的前一天中午十二点之前方能取消
     */
    private boolean getCancelLegal(String time) {
        if (TextUtils.isEmpty(time)) {
            return false;
        }
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        GregorianCalendar gcd = new GregorianCalendar();
        try {
            Date date = simpleDateFormat.parse(time);
            gcd.setTime(date);
            return (gcd.getTimeInMillis() - System.currentTimeMillis()) / (1000 * 3600) > 12;
        } catch (ParseException e) {
            e.printStackTrace();
            Logs.logException(e);
            return false;
        }
    }

    public String getAdvance_id() {
        return this.advance_id;
    }

    public String getScenic_id() {
        return this.scenic_id;
    }

    public String getAdvance_date() {
        return this.advance_date;
    }

    public int getStatus() {
        return this.status;
    }

    public String getScenic_name() {
        return this.scenic_name;
    }

    public String getThumbnail() {
        return this.thumbnail;
    }

    public String getAddress() {
        return this.address;
    }

    public boolean isTicketAble() {
        return this.ticketAble;
    }

    public void setAdvance_id(String advance_id) {
        this.advance_id = advance_id;
    }

    public void setScenic_id(String scenic_id) {
        this.scenic_id = scenic_id;
    }

    public void setAdvance_date(String advance_date) {
        this.advance_date = advance_date;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public void setCancel_reason(String cancel_reason) {
        this.cancel_reason = cancel_reason;
    }

    public void setScenic_name(String scenic_name) {
        this.scenic_name = scenic_name;
    }

    public void setThumbnail(String thumbnail) {
        this.thumbnail = thumbnail;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public void setCancelable(boolean cancelable) {
        this.cancelable = cancelable;
    }

    public void setTicketAble(boolean ticketAble) {
        this.ticketAble = ticketAble;
    }

    public void setStatusStr(String statusStr) {
        this.statusStr = statusStr;
    }

    public void setStatusColor(int statusColor) {
        this.statusColor = statusColor;
    }

    public boolean equals(final Object o) {
        if (o == this) return true;
        if (!(o instanceof AppointBean)) return false;
        final AppointBean other = (AppointBean) o;
        if (!other.canEqual((Object) this)) return false;
        final Object this$advance_id = this.getAdvance_id();
        final Object other$advance_id = other.getAdvance_id();
        if (this$advance_id == null ? other$advance_id != null : !this$advance_id.equals(other$advance_id))
            return false;
        final Object this$scenic_id = this.getScenic_id();
        final Object other$scenic_id = other.getScenic_id();
        if (this$scenic_id == null ? other$scenic_id != null : !this$scenic_id.equals(other$scenic_id))
            return false;
        final Object this$advance_date = this.getAdvance_date();
        final Object other$advance_date = other.getAdvance_date();
        if (this$advance_date == null ? other$advance_date != null : !this$advance_date.equals(other$advance_date))
            return false;
        if (this.getStatus() != other.getStatus()) return false;
        final Object this$cancel_reason = this.getCancel_reason();
        final Object other$cancel_reason = other.getCancel_reason();
        if (this$cancel_reason == null ? other$cancel_reason != null : !this$cancel_reason.equals(other$cancel_reason))
            return false;
        final Object this$scenic_name = this.getScenic_name();
        final Object other$scenic_name = other.getScenic_name();
        if (this$scenic_name == null ? other$scenic_name != null : !this$scenic_name.equals(other$scenic_name))
            return false;
        final Object this$thumbnail = this.getThumbnail();
        final Object other$thumbnail = other.getThumbnail();
        if (this$thumbnail == null ? other$thumbnail != null : !this$thumbnail.equals(other$thumbnail))
            return false;
        final Object this$address = this.getAddress();
        final Object other$address = other.getAddress();
        if (this$address == null ? other$address != null : !this$address.equals(other$address))
            return false;
        if (this.isCancelable() != other.isCancelable()) return false;
        if (this.isTicketAble() != other.isTicketAble()) return false;
        final Object this$statusStr = this.getStatusStr();
        final Object other$statusStr = other.getStatusStr();
        if (this$statusStr == null ? other$statusStr != null : !this$statusStr.equals(other$statusStr))
            return false;
        if (this.getStatusColor() != other.getStatusColor()) return false;
        return true;
    }

    protected boolean canEqual(final Object other) {
        return other instanceof AppointBean;
    }

    public int hashCode() {
        final int PRIME = 59;
        int result = 1;
        final Object $advance_id = this.getAdvance_id();
        result = result * PRIME + ($advance_id == null ? 43 : $advance_id.hashCode());
        final Object $scenic_id = this.getScenic_id();
        result = result * PRIME + ($scenic_id == null ? 43 : $scenic_id.hashCode());
        final Object $advance_date = this.getAdvance_date();
        result = result * PRIME + ($advance_date == null ? 43 : $advance_date.hashCode());
        result = result * PRIME + this.getStatus();
        final Object $cancel_reason = this.getCancel_reason();
        result = result * PRIME + ($cancel_reason == null ? 43 : $cancel_reason.hashCode());
        final Object $scenic_name = this.getScenic_name();
        result = result * PRIME + ($scenic_name == null ? 43 : $scenic_name.hashCode());
        final Object $thumbnail = this.getThumbnail();
        result = result * PRIME + ($thumbnail == null ? 43 : $thumbnail.hashCode());
        final Object $address = this.getAddress();
        result = result * PRIME + ($address == null ? 43 : $address.hashCode());
        result = result * PRIME + (this.isCancelable() ? 79 : 97);
        result = result * PRIME + (this.isTicketAble() ? 79 : 97);
        final Object $statusStr = this.getStatusStr();
        result = result * PRIME + ($statusStr == null ? 43 : $statusStr.hashCode());
        result = result * PRIME + this.getStatusColor();
        return result;
    }

    public String toString() {
        return "AppointBean(advance_id=" + this.getAdvance_id() + ", scenic_id=" + this.getScenic_id() + ", advance_date=" + this.getAdvance_date() + ", status=" + this.getStatus() + ", cancel_reason=" + this.getCancel_reason() + ", scenic_name=" + this.getScenic_name() + ", thumbnail=" + this.getThumbnail() + ", address=" + this.getAddress() + ", cancelable=" + this.isCancelable() + ", ticketAble=" + this.isTicketAble() + ", statusStr=" + this.getStatusStr() + ", statusColor=" + this.getStatusColor() + ")";
    }
}
